 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title><spring:message code="message.lable.DICzhuanJiaLeiXingChaKan"/></title>
<%@ include file="/WEB-INF/component/commonCSS.jsp"%>
<!--[if lt IE 9]>
    <script src="lib/js/html5shiv.min.js"></script>
    <script src="lib/js/respond.min.js"></script>
<![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">

    <section class="content-header">
        <h1><spring:message code="message.lable.DICzhuanJiaLeiXingChaKan"/></h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.DicManage"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.experttypeDic"/></a></li>
        </ol>
    </section>
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
            <form action="${ctx}/dicExperttype/exportExcel.html" id="exportExcel" method="post">
            <input id="fileName" name="fileName" type="hidden" value="<spring:message code="message.lable.expertxls"/>" />
                    <div class="input">
           			<div class="textalign"><spring:message code="message.listForm.zhuanJiaLeiXingMingCheng"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="expertTypeName" name="expertTypeName" placeholder="<spring:message code="message.listForm.zhuanJiaLeiXingMingCheng"/>"  />
                    </div>
                    
                    <div class="textalign"><spring:message code="message.lable.status"/>：</div>
                    <div class="boxinput">
                       <select id="status" name="status" class="textinput">
                           	<option value="" ><spring:message code="message.select.option"/></option>
                            <option value="1" ><spring:message code="message.button.start"/></option>
                            <option value="0" ><spring:message code="message.button.stop"/></option>
                           </select>
                     </div>
                     <div class="textalign" >
                    <button type="button" onclick="likeQuery();" class="btn btn-success btn-sm" id="selectDicCompType"> <spring:message code="message.button.seachSpacing"/></button>
                </div>
                </div>
                </form>
            </div>
        </div>
       <table class="jqgrid" id="gridlist"></table>
       <div id="gridpage"></div>
       <div class=" box box-warning bottongroup">
           <ms:btn url="/dicExperttype/add.html"><label id="addNew" class="btn btn-default btn-sm"><spring:message code="message.button.addSpacing"/></label></ms:btn>
           <ms:btn url="/dicExperttype/enable.html"><label id="allStart" class="btn btn-default btn-sm"><spring:message code="message.button.startSpacing"/></label></ms:btn>
           <ms:btn url="/dicExperttype/disable.html"><label id="allDelete" class="btn btn-default btn-sm"><spring:message code="message.button.stopSpacing"/></label></ms:btn>
           <label onclick="exportExcel();" class="btn btn-default btn-sm"><spring:message code="message.lable.daoChu"/></label>
           
       </div>
      
        <div class="modal fade" id="exampleModal" tabindex="-1" >
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-primary">
                        <button type="button" class="close" data-dismiss="modal" ><span >&times;</span></button>
                        <h5 class="modal-title" id="exampleModalLabel"><spring:message code="message.lable.DICzhuanJiaLeiXingXinZeng"/></h5>
                    </div>
                    <div class="modal-body">
                  <form>
                    <div class="form-group form-group-xs">
                        <label for="recipient-name" class=" control-label"><spring:message code="message.listForm.yiJizhuanJiaLeiXingMingCheng"/>：</label>
                        <div class="">
                            <input type="text" class="form-control"  id="txtOneName" placeholder="<spring:message code="message.listForm.yiJizhuanJiaLeiXingMingCheng"/>" maxlength="128">
                        </div>
                    </div>
                    
                   <div id="addTwoForm" style="display:none">
                    <button type="button" id="addTwoLevel" class="btn btn-primary btn-sm"><spring:message code="message.listForm.tianJiaErJizhuanJiaLeiXing"/></button>
                    </div>
                            <div class="form-group form-group-xs" id="twoForm" style="display:none">
                                <label for="recipient-name" class=" control-label"><spring:message code="message.listForm.erJizhuanJiaLeiXingMingCheng"/>：</label>
                                <div class="">
                                    <input type="text" class="form-control" id="txtTwoName" placeholder="<spring:message code="message.listForm.erJizhuanJiaLeiXingMingCheng"/>" maxlength="128">
                                </div>
                           </div>
                        
                    <div id="addThreeForm" style="display:none">
                    <button type="button" id="addThreeLevel" class="btn btn-primary btn-sm"><spring:message code="message.listForm.tianJiaSanJizhuanJiaLeiXing"/></button>
                    </div>
                            <div class="form-group form-group-xs" id="threeForm" style="display:none">
                                <label for="recipient-name" class=" control-label"><spring:message code="message.listForm.sanJizhuanJiaLeiXingMingCheng"/>：</label>
                                <div class="">
                                    <input type="text" class="form-control" id="txtThreeName" placeholder="<spring:message code="message.listForm.erJizhuanJiaLeiXingMingCheng"/>" maxlength="128">
                                </div>
                           </div>
                           <input type="hidden" id="addFatherId"/>
                </form>
                    </div>
              <div class="modal-footer">
                  <button type="button" onclick="addSave();" class="btn btn-primary btn-sm"><spring:message code="message.button.saveSpacing"/></button>
              </div>
            </div>
         </div>
      </div>
      
      <!-- -----修改----- -->
      <div class="modal fade" id="editModal" tabindex="-1" >
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-primary">
                        <button type="button" class="close" data-dismiss="modal" ><span >&times;</span></button>
                        <h5 class="modal-title" id="editModalLabel"><spring:message code="message.lable.DICzhuanJiaLeiXingBianJi"/></h5>
                    </div>
                    <div class="modal-body">
                  <form>
                    <div class="form-group form-group-xs" id="oneEditDiv">
                        <label for="recipient-name" class=" control-label"><spring:message code="message.listForm.yiJizhuanJiaLeiXingMingCheng"/>：</label>
                        <div class="">
                            <input type="text" class="form-control"  id="editOneName" placeholder="<spring:message code="message.listForm.yiJizhuanJiaLeiXingMingCheng"/>" maxlength="128">
                        </div>
                    </div>
                    
                            <div class="form-group form-group-xs" id="twoEditDiv" >
                                <label for="recipient-name" class=" control-label"><spring:message code="message.listForm.erJizhuanJiaLeiXingMingCheng"/>：</label>
                                <div class="">
                                    <input type="text" class="form-control" id="editTwoName" placeholder="<spring:message code="message.listForm.erJizhuanJiaLeiXingMingCheng"/>" maxlength="128">
                                </div>
                           </div>
                        
                            <div class="form-group form-group-xs" id="threeEditDiv" >
                                <label for="recipient-name" class=" control-label"><spring:message code="message.listForm.sanJizhuanJiaLeiXingMingCheng"/>：</label>
                                <div class="">
                                    <input type="text" class="form-control" id="editThreeName" placeholder="<spring:message code="message.listForm.sanJizhuanJiaLeiXingMingCheng"/>" maxlength="128">
                                </div>
                           </div>
                           <input type="hidden" id="editId"/>
                </form>
                    </div>
              <div class="modal-footer">
                  <button type="button" onclick="editSave();" class="btn btn-primary btn-sm"><spring:message code="message.button.saveSpacing"/></button>
              </div>
            </div>
         </div>
      </div>
    </section>
   
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
  //绑定回车
    $('#expertTypeName,#status').bind('keydown', function(event) {
        if (event.keyCode == "13") {
            $('#selectDicCompType').click();
        }
    }); 
    
        var addType = 0;//1新增 ，2新增二级类型，3新增三级类型 
        var editType=0;//1修改一级类型，2修改二级类型，3修改三级类型
        var addNewType=1;//1只新增一级 ，2新增一级和二级，3新增一级二级三级
        
       
        
        
      //新增
        $(function () {
            $("#expertTypeName").focus();//加载页面光标在通用名上
            
            
             $('#addNew').click(function () {
                 addType=1;
                 addNewType = 1;
                $("#txtOneName").attr("readonly",false);
                $("#addTwoForm").show();
                $("#twoForm").hide();
                
                $("#txtTwoName").attr("readonly",false);
                $("#addThreeForm").hide();
                $("#threeForm").hide();
                
                $('.modal-title').html('<spring:message code="message.lable.DICzhuanJiaLeiXingXinZeng"/>');
                $('#txtOneName').val("");
                $('#txtTwoName').val("");
                $('#txtThreeName').val("");
                
                $('#exampleModal').modal({
                    keyboard: true
                });
            });
            
            
          //列表展示
            $("#gridlist").jqGrid({
                url: "${ctx}/dicExperttype/getDicExperttypeList.html",
                mtype: "post",
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: [
                    'id',
                    'code',
                    '<spring:message code="message.jqGrid.cz"/>',
                    '<spring:message code="message.listForm.zhuanJiaLeiXingMingCheng"/>',
                    '<spring:message code="message.listForm.yiJizhuanJiaLeiXingMingCheng"/>', 
                    '<spring:message code="message.listForm.erJizhuanJiaLeiXingMingCheng"/>', 
                    '<spring:message code="message.listForm.sanJizhuanJiaLeiXingMingCheng"/>', 
                    '<spring:message code="message.lable.status"/>'
                    
                ],
                colModel: [
                    { name: 'dicExperttypeId', width: 10,hidden:true, align:"center", sortable: false},  
                    { name: 'expertTypeCode', width: 10, align:"center",hidden:true, sortable: false},
                    { name: 'operate', width: 4, align:"left", sortable: false,
                        formatter : function(val, opts, rowdata) {
                            var secoLevelName;
                            var thirdLevelName; 
                            if(rowdata.secoLevelName==null){
                                secoLevelName = "";
                            }else{
                                secoLevelName = rowdata.secoLevelName;
                            }
                            if(rowdata.thirdLevelName==null){
                                thirdLevelName = "";
                            }else{
                                thirdLevelName = rowdata.thirdLevelName;
                            }
                            var expertTypeName = "";
                            if(rowdata.thirdLevelName == null){
                                if(rowdata.secoLevelName == null){
                                    expertTypeName = rowdata.firstLevelName;
                                }else{
                                    expertTypeName = rowdata.secoLevelName;
                                }
                            }else{
                                expertTypeName = rowdata.thirdLevelName;
                            }
                            var str =  "<ms:btn url='/dicExperttype/edit.html'><a href='javascript:edit(\""+rowdata.dicExperttypeId+"\",\""+rowdata.firstLevelName+"\",\""+secoLevelName+"\",\""+thirdLevelName+"\");' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.bianJi"/>'></a></ms:btn>";
                            str += "<ms:btn url='/dicExperttypeLog/log.html'><a href='${ctx}/dicExperttypeLog/log.html?dicExperttypeId="+rowdata.dicExperttypeId+"&expertTypeName="+expertTypeName+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -120px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.weiHuJiLu"/>'></a></ms:btn>";
                            if(rowdata.secoLevelName){
                                if(!rowdata.thirdLevelName){
                                    str += "<ms:btn url='/dicExperttype/addThree.html'><a href='javascript:addThirdLevel(\""+rowdata.dicExperttypeId+"\",\""+rowdata.firstLevelName+"\",\""+rowdata.secoLevelName+"\");' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px -60px' class='opIcon' title='<spring:message code="message.jqGrid.cz.xinZengSanJiLeiXing"/>'></a></ms:btn>";
                                }
                            }else{
                                    str += "<ms:btn url='/dicExperttype/addTwo.html'><a href='javascript:addSecoLevel(\""+rowdata.dicExperttypeId+"\",\""+rowdata.firstLevelName+"\");'  style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -140px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.xinZengErJiLeiXing"/>')></a></ms:btn>";
                            }
                            return str;
                            }
                    },
                    { name: 'expertTypeName', width: 8, align:"center", sortable: false,hidden:true},
                    { name: 'firstLevelName', width: 8, align:"center", sortable: false },
                    { name: 'secoLevelName', width: 8, align:"center", sortable: false },
                    { name: 'thirdLevelName', width: 12, align:"center", sortable: false },
                    { name: 'status', width: 3, align: 'center', sortable: false,
                        cellattr:function (rowId, val, rawObject, cm) {
                            if(val == '停用'){
                                return 'style="color:red"';
                            }
                        },
                        formatter : function(val,opts,rowdata){
                            if(rowdata.status==1){
                                return "<spring:message code="message.button.start"/>";
                            }else{
                                return "<spring:message code="message.button.stop"/>";
                            }
                        }   
                    }
                   
                ],
                rowNum: 20,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                pager: "#gridpage",
                viewrecords: true,
                multiselect: true, 
                caption: "<spring:message code="message.list.experttypeDiclist"/>",
                gridComplete:function(){
                    //序号列宽度自适应（参数为jqgridID）
                    autoRNWidth("gridlist");
                    //数据只有一条时默认选中（参数为jqgridID）
                    selectByOneData("gridlist");
                },
                jsonReader: {
                    repeatitems: false,
                    id: "dicExperttypeId"
                }

            });
            
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            
            $(window).trigger("resize");
            //moreNoMore();
        });
        
        
        
        
       
        
        
        
        //新增保存
        function addSave(){
            var list = [];
            var firstLevelName = $.trim($("#txtOneName").val());
            var secoLevelName = $.trim($("#txtTwoName").val());
            var thirdLevelName = $.trim($("#txtThreeName").val()); 
             if(addType==1){
                 if(addNewType==1){
                     if (!validate1()) {
                        return;
                     }
                     list.push({"fatherId":"0","expertTypeName":firstLevelName});
                 }else if(addNewType==2){
                     if (!validate2()) {
                        return;
                     }
                     if(firstLevelName==secoLevelName){
                         $.alert('<spring:message code="message.listForm.zhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.buNengChongFu"/>','warn');
                         return;
                     }else if(firstLevelName.length>10){
                         $.alert("<spring:message code="message.listForm.zhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.changDuGuoChang"/><spring:message code="message.yanZheng.qingChongXinShuRu"/>","warn");
                         return;
                     }
                     list.push({"fatherId":"0","expertTypeName":firstLevelName});
                     list.push({"fatherId":"1","expertTypeName":secoLevelName});
                 }else if(addNewType==3){
                     if (!validate3()) {
                        return;
                     }
                     if(firstLevelName==thirdLevelName){
                         $.alert('<spring:message code="message.listForm.zhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.buNengChongFu"/>','warn');
                         return;
                     }
                     if(secoLevelName==thirdLevelName){
                         $.alert('<spring:message code="message.listForm.zhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.buNengChongFu"/>','warn');
                         return;
                     }else if(secoLevelName.length>10){
                         $.alert("<spring:message code="message.listForm.zhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.changDuGuoChang"/><spring:message code="message.yanZheng.qingChongXinShuRu"/>","warn");
                         return;
                     }
                     list.push({"fatherId":"0","expertTypeName":firstLevelName});
                     list.push({"fatherId":"1","expertTypeName":secoLevelName});
                     list.push({"fatherId":"2","expertTypeName":thirdLevelName});
                 }
             }
             if(addType==2){
                if (!validate2()) {
                        return;
                }
                 list.push({"fatherId":$("#addFatherId").val(),"expertTypeName":secoLevelName});     
             }
             if(addType==3){
                 if (!validate3()) {
                        return;
                 }
                 list.push({"fatherId":$("#addFatherId").val(),"expertTypeName":thirdLevelName});        
             }
                $.HN.message.confirm('<spring:message code="message.HN.alert.OkSaveYESorNO"/>', '', '').on(function (e) {
                   if (e) {
                    $.ajax({
                       type: "POST",
                       url: "${ctx}/dicExperttype/add.html",
                       data:{
                           "array" : json.jsonToString(list)
                       },
                       dataType:"json",
                       success: function(result){
                           if(result.success){
                            $.alert("<spring:message code="message.HN.alert.success"/>", "success");
                               $("#gridlist").jqGrid('setGridParam',{page:1}).trigger("reloadGrid");
                            $('#exampleModal').modal('hide');
                           }else{
                               $.alert(result.msg || "<spring:message code="message.HN.alert.fail"/>", "error");
                                   }
                               }
                        });
                    }
             });
        } 
        
        //编辑
        function edit(dicExperttypeId,firstLevelName,secoLevelName,thirdLevelName){
            $('.modal-title').html('<spring:message code="message.lable.DICzhuanJiaLeiXingBianJi"/>');
            $("#editId").val(dicExperttypeId);
            $("#threeEditDiv").show();
            $("#twoEditDiv").show();
            $("#editTwoName").attr("readonly",false);
            $("#editOneName").attr("readonly",false);
            $("#editOneName").val(firstLevelName);
            $("#editTwoName").val(secoLevelName);
            $("#editThreeName").val(thirdLevelName);
            if(thirdLevelName){
                $("#editTwoName").attr("readonly",true);
            }
            if(secoLevelName){
                $("#editOneName").attr("readonly",true);
            }
            
            if(!thirdLevelName){
                $("#threeEditDiv").hide();
            }
            if(!secoLevelName){
                $("#twoEditDiv").hide();
            }
            if(!secoLevelName&&!thirdLevelName){
                editType = 1;
            }else if(secoLevelName&&thirdLevelName) {
                editType = 3;
            }else {
                editType = 2;
            }
            $('#editModal').modal({
                keyboard: true
            });
                    
                
        }
        
        //编辑保存
        function editSave(){
            var dicExperttypeId = $.trim($("#editId").val());
            var firstLevelName = $.trim($("#editOneName").val());
            var secoLevelName = $.trim($("#editTwoName").val());
            var thirdLevelName = $.trim($("#editThreeName").val());
            var typeName = "";
            if(editType==1){
                if (firstLevelName == null || firstLevelName == "") {
                    $.alert("<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.listForm.yiJizhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
                    return;
                } else if(firstLevelName.length>100){
                    $.alert("<spring:message code="message.listForm.yiJizhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.changDuGuoChang"/>","warn");
                    return;
                }
                typeName = firstLevelName;
            }
            if(editType==2){
                if (secoLevelName == null || secoLevelName == "") {
                    $.alert("<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.listForm.erJizhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
                    return;
                } else if(secoLevelName.length>100){
                    $.alert("<spring:message code="message.listForm.erJizhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.changDuGuoChang"/>","warn");
                    return;
                }
                if(firstLevelName==secoLevelName){
                    $.alert("<spring:message code="message.listForm.zhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.buNengChongFu"/>", "warn");
                    return;
                }
                typeName = secoLevelName;
            }
            if(editType==3){
                if (thirdLevelName == null || thirdLevelName == "") {
                    $.alert("<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.listForm.sanJizhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
                    return;
                } else if(thirdLevelName.length>100){
                    $.alert("<spring:message code="message.listForm.sanJizhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.changDuGuoChang"/>","warn");
                    return;
                }
                if(firstLevelName==thirdLevelName){
                    $.alert('<spring:message code="message.listForm.zhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.buNengChongFu"/>','warn');
                    return;
                }
                if(secoLevelName==thirdLevelName){
                    $.alert('<spring:message code="message.listForm.zhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.buNengChongFu"/>','warn');
                    return;
                }
                typeName = thirdLevelName;
            }
            $.HN.message.confirm('<spring:message code="message.HN.alert.OkSaveYESorNO"/>', '', '').on(function (e) {
                if (e) {
                 $.ajax({
                    type: "POST",
                    url: "${ctx}/dicExperttype/edit.html",
                    data:{
                        dicExperttypeId:dicExperttypeId,
                        typeName:typeName
                    },
                    dataType:"json",
                    success: function(result){
                        if(result.success){
                         $.alert("<spring:message code="message.HN.alert.success"/>", "success");
                            $("#gridlist").jqGrid('setGridParam',{page:1}).trigger("reloadGrid");
                         $('#editModal').modal('hide');
                        }else{
                           $.alert(result.msg || "<spring:message code="message.HN.alert.fail"/>", "error");
                                }
                            }
                     });
                 }
          }); 
        }
        //添加二级类型
        function addSecoLevel(fatherId,firstLevelName){
            addType=2;
            $("#addFatherId").val(fatherId);
            $("#txtOneName").attr("readonly",true);//一级只读
            $("#addTwoForm").hide();//添加二级按钮隐藏
            $("#twoForm").show();//二级显示
            $("#txtTwoName").attr("readonly",false);//解除二级只读
            $('.modal-title').html('<spring:message code="message.listForm.tianJiaErJizhuanJiaLeiXing"/>');
            $("#txtOneName").val(firstLevelName);//一级赋值
            $('#txtTwoName').val("");//二级值清空
            $("#addThreeForm").hide();//添加三级按钮隐藏
            $("#threeForm").hide();//三级隐藏
            $('#txtThreeName').val("");//三级值清空
            $('#exampleModal').modal({
                keyboard: true
            });
        }
       
        //添加三级类型
        function addThirdLevel(fatherId,firstLevelName,secoLevelName){
            addType=3;
            $("#addFatherId").val(fatherId);
            $('.modal-title').html('<spring:message code="message.listForm.tianJiaSanJizhuanJiaLeiXing"/>');
            $("#txtOneName").attr("readonly",true);//一级只读
            $("#addTwoForm").hide();//添加二级按钮隐藏
            $("#twoForm").show();//二级显示
            $("#txtTwoName").attr("readonly",true);//二级只读
            $("#txtOneName").val(firstLevelName);//一级赋值
            $('#txtTwoName').val(secoLevelName);//二级赋值
            $("#addThreeForm").hide();//添加三级按钮隐藏
            $("#threeForm").show();//三级显示
            $('#txtThreeName').val("");//三级值清空
            $('#exampleModal').modal({
                keyboard: true
            });
        }
        
        
      //点击添加二级类型按钮
        $("#addTwoLevel").click(function(){
             if (!validate1()) {
                    return;
            }
            $.post("${ctx}/dicExperttype/checkRepeat.html", {
                expertTypeName : $("#txtOneName").val(),
            }, function(result) {
                if (result.success) {
                    addNewType =2;
                    $("#twoForm").show();
                    $("#addTwoForm").hide();
                    $("#txtOneName").attr("readonly",true);
                    $("#addThreeForm").show();
                } else {
                    $.alert(result.msg||"<spring:message code="message.HN.alert.fail"/>", "error");
                }
            }, "json");
        });
      
      //点击添加三级类型按钮 
        $("#addThreeLevel").click(function(){
             if (!validate2()) {
                    return;
            }
             if($.trim($("#txtOneName").val())==$.trim($("#txtTwoName").val())){
                $.alert('<spring:message code="message.listForm.zhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.buNengChongFu"/>','warn');
                return;
            }/* else if(secoLevelName.length>100){
                $.alert("<spring:message code="message.listForm.sanJizhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.changDuGuoChang"/>","warn");
                return;
            } */
           $.post("${ctx}/dicExperttype/checkRepeat.html", {
                expertTypeName : $("#txtTwoName").val(),
            }, function(result) {
                if (result.success) {
                    addNewType = 3;
                    $("#threeForm").show();
                    $("#addThreeForm").hide();
                    $("#txtTwoID").attr("readonly",true);
                    $("#txtTwoName").attr("readonly",true);
                } else {
                    $.alert(result.msg||"<spring:message code="message.HN.alert.fail"/>", "error");
                }
            }, "json"); 
        });
      
      
        
     
        /* 一级类型验证 */
         function validate1() {
            var typeName = $.trim($("#txtOneName").val());
            if (typeName == null || typeName == "") {
                $.alert("<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.listForm.yiJizhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
                return false;
            } else if(typeName.length>100){
                $.alert("<spring:message code="message.listForm.yiJizhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.changDuGuoChang"/>","warn");
                return false;
            }

            return true;
        }
        
        /* 二级类型验证 */
        function validate2() {
            var typeName = $.trim($("#txtTwoName").val());
            if (typeName == null || typeName == "") {
                $.alert("<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.listForm.erJizhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
                return false;
            } else if(typeName.length>100){
                $.alert("<spring:message code="message.listForm.erJizhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.changDuGuoChang"/>", "warn");
                return false;
            }

            
            return true;
        }
        
        /* 三级类型验证 */
        function validate3() {

            var typeName = $.trim($("#txtThreeName").val());
            if (typeName == null || typeName == "") {
                $.alert("<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.listForm.sanJizhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
                return false;
            } else if(typeName.length>100){
                $.alert("<spring:message code="message.listForm.sanJizhuanJiaLeiXingMingCheng"/><spring:message code="message.yanZheng.changDuGuoChang"/>", "warn");
                return false;
            }
            
            return true;
        }
        
        //查询
        function likeQuery(page){
            if (page == ""){
                page = 1;
            }
            var expertTypeName = $("#expertTypeName").val();
            var status = $("#status").val();
            $("#gridlist").jqGrid('setGridParam',{  
                postData:{
                    "expertTypeName":expertTypeName,
                    "status":status
                },page:page
            }).trigger("reloadGrid"); //重新载入  
        }
        
        
        /* 启用停用（包含批量） */
        $('#allDelete').click(function(){
            batchChangeStatus(0);
        });
        $('#allStart').click(function(){
            batchChangeStatus(1);
        });   
        
        //启用、停用
        function batchChangeStatus(status) {
            var msg = "";
            var url = "";
            if (status == 1){
                msg = "<spring:message code="message.button.start"/>";
                url = "${ctx}/dicExperttype/disable.html";
            } else if (status == 0){
                msg = "<spring:message code="message.button.stop"/>";
                url = "${ctx}/dicExperttype/enable.html"; 
            }
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
                $.alert("<spring:message code="message.lable.pleaseSelect"/>"+msg+"<spring:message code="message.listForm.zhuanJiaLeiXing"/>", "warn");
                return;
            }
            
            var str = "";
            var names = "";
                for (var i = 0;i < rowIds.length; i++){
                    var rowdata = $("#gridlist").jqGrid('getRowData', rowIds[i]);
                    if (status == 1){
                        if (rowdata.status == "<spring:message code="message.button.stop"/>"){
                            if(rowdata.thirdLevelName == ""){
                                if(rowdata.secoLevelName == ""){
                                    names += rowdata.firstLevelName+",";
                                    str += rowIds[i]+",";
                                }else{
                                    names += rowdata.secoLevelName+",";
                                    str += rowIds[i]+",";
                                }
                            }else{
                                names += rowdata.thirdLevelName+",";
                                str += rowIds[i]+",";
                            }
                            
                        }
                    } else {
                        if (rowdata.status == "<spring:message code="message.button.start"/>"){
                            if(rowdata.thirdLevelName == ""){
                                if(rowdata.secoLevelName == ""){
                                    names += rowdata.firstLevelName+",";
                                    str += rowIds[i]+",";
                                }else{
                                    names += rowdata.secoLevelName+",";
                                    str += rowIds[i]+",";
                                }
                            }else{
                                names += rowdata.thirdLevelName+",";
                                str += rowIds[i]+",";
                            }
                        }
                    }
                }
                if (names != ""){
                    names = names.substring(0,names.length-1);
                } else {
                    $.alert("<spring:message code="message.lable.pleaseSelect"/>"+msg+"<spring:message code="message.lable.OKData"/>", "warn");
                    return;
                }
            
              $.HN.message.confirm('<spring:message code="message.lable.OKYES"/>'+msg+'<spring:message code="message.lable.FlowerDataYESorNo"/><br/>'+names, '', '').on(function (e) {
              if (e) {
                    if (str.length > 0){
                        str = str.substring(0,str.length-1);
                    }
            var list = [];
            for (var i=0; i<rowIds.length; i++) {
                rowId = rowIds[i];
                var rowData = $("#gridlist").jqGrid('getRowData',rowId);
                list.push({"dicExperttypeId":rowData.dicExperttypeId,"expertTypeCode":rowData.expertTypeCode, "status":status});
            }
            $.post(url, {
                "array" : json.jsonToString(list)
            }, function(result) {
                if (result.success) {
                    $.alert("<spring:message code="message.HN.alert.chengGong"/>"+msg+result.conditions.count+"<spring:message code="message.HN.alert.tiaoShuJu"/>", "success");
                    likeQuery();
                    gridSerch($("#gridlist").jqGrid('getGridParam','page'));
                } else {
                    $.alert(result.msg || "<spring:message code="message.HN.alert.fail"/>", "error");
                }
            }, "json");
                }
            }); 
        } 
        
        function exportExcel(){
    		$.HN.message.confirm('<spring:message code="message.lable.OKExport"/>&nbsp;<spring:message code="message.lable.expertxls"/>&nbsp;<spring:message code="message.lable.ma"/>', '', '').on(function (e) {
	               if (e) {
	            		  $("#exportExcel").submit();
			
	               }
         	 }); 
         	
    	} 
    </script>
</body>
</html>